package src.Games;

import src.Players.Player;
import java.util.*;

public class CastleWars {
	ArrayList<Integer> saraIds = new ArrayList<Integer>();
	ArrayList<Integer> zammyIds = new ArrayList<Integer>();
	private Player p;
	
	public CastleWars() {
	}
	
	public void addPlayerSara(Player p) {
		if(saraIds.size() < 5) {
			try {
				saraIds.add(1, p.playerIndex);
				System.out.println("sara, "+saraIds.size()+" : added "+p.playerIndex);
			} catch(Exception e) {
				e.printStackTrace();
			}
		} else {
			p.frame.sendMessage(p, "This team is full!");
			return;
		}
	}
	
	public void addPlayerZammy(Player p) {
		if(zammyIds.size() < 5) {
			try {
				zammyIds.add(1, p.playerIndex);
				System.out.println("zammy, "+zammyIds.size()+" : added "+p.playerIndex);
			} catch(Exception e) {
				e.printStackTrace();
			}
		} else {
			p.frame.sendMessage(p, "This team is full!");
			return;
		}
	}
	
	public void startGame() {
		if(saraIds.size() >= 5 && zammyIds.size() >= 5) {
			for(int i : saraIds) {
				p.teleportToPoint(1111, 1111, 0);
				System.out.println("sara, "+saraIds.size()+" : began "+i);
			}
			for(int i : zammyIds) {
				p.teleportToPoint(1111, 1111, 0);
				System.out.println("zammy, "+zammyIds.size()+" : began "+i);
			}
		} else {
			System.out.println("castle wars : insufficient players");
			return;
		}
	}
	
	public void endGame() {
		for(int i : saraIds) {
			p.teleportToPoint(1111, 1111, 0);
			saraIds.remove(i);
			System.out.println("sara, "+saraIds.size()+" : removed "+i);
		}
		for(int i : zammyIds) {
			p.teleportToPoint(1111, 1111, 0);
			zammyIds.remove(i);
			System.out.println("zammy, "+zammyIds.size()+" : removed "+i);
		}
	}
	
	private void clearLists() { // as a precaution
		saraIds.clear();
		zammyIds.clear();
	}
	
	public void getPlayers() { // as a precaution
		System.out.println("zammy size : "+zammyIds.size()+", is empty : "+zammyIds.isEmpty());
		System.out.println("sara size : "+saraIds.size()+", is empty : "+saraIds.isEmpty());
	}
}